
import logging
import uuid
import glob
import json
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger(__name__)


def get_mac_address():
    """获取系统的MacAddress"""

    if glob.glob("/root/.mac"):
        
        with open('/root/.mac') as f:

            mac = f.read().strip()
    else:    
        node = uuid.getnode()

        mac = uuid.UUID(int=node).hex[-12:]

    return mac

def get_mqtt_data_center_host():

    if glob.glob("/root/.mqtt_data_center_host"):
        
        with open('/root/.mqtt_data_center_host') as f:

            info = json.loads(f.read())
    else:    
        
        info = {
            "host": "10.168.35.31", 
            "port": "1883"
        }

    return info



MAC = get_mac_address()

# MQTT_DATA_CENTER_HOST = "broker.emqx.io"
# MQTT_DATA_CENTER_PORT = 1883
MQTT_DATA_CENTER_HOST = get_mqtt_data_center_host()["host"]
MQTT_DATA_CENTER_PORT = int(get_mqtt_data_center_host()["port"])
MQTT_DATA_CENTER_USERNAME = ""
MQTT_DATA_CENTER_PASSWD = ""
MQTT_DATA_CENTER_SUBSCRIPTION_TOPIC = f"iot/devices/test/baina/{MAC}/allinone/rx"
MQTT_DATA_CENTER_PUBLISH_TOPIC = f"iot/devices/test/baina/{MAC}/allinone/tx"

# 主站MQTT
MQTT_LOCAL_HOST = "127.0.0.1"
MQTT_LOCAL_PORT = 1883
MQTT_LOCAL_SUBSCRIPTION_TOPIC = "base_station_publish_channel"
MQTT_LOCAL_PUBLISH_TOPIC = "main_station_publish_channel"
# MQTT_LOCAL_PUBLISH_TRANSCATIONS_TOPIC = "main_station_publish_transactions_channel" 
